//
//  BCUserCenterCoinDataTypeView.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2018/11/16.
//  Copyright © 2018年 guoshikeji. All rights reserved.
//

#import "BCUserCenterCoinDataTypeView.h"


@interface BCUserCenterCoinDataButtonView : QMUIButton

/**
 *customTitleLabel
 */
@property (nonatomic, strong) UILabel *customTitleLabel;

/**
 *dataLabel
 */
@property (nonatomic, strong) UILabel *dataLabel;


+ (CGFloat)defaultHeight;

@end

@implementation BCUserCenterCoinDataButtonView

+ (UIFont *)customTitleFont {
    return [UIFont systemFontOfSize:13 weight:UIFontWeightRegular];
}
+ (CGFloat)customTitleHeight {
    return [self customTitleFont].lineHeight+2;
}
+ (UIFont *)dataFont {
    return [UIFont systemFontOfSize:20 weight:UIFontWeightMedium];
}
+ (CGFloat)dataHeight {
    return [self dataFont].lineHeight+2;
}

+ (CGFloat)defaultHeight {
    CGFloat height = 0;
    height += [self customTitleHeight];
    height += 5.0;
    height += [self dataHeight];
    return height;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setupSubviews];
    }
    return self;
}

- (void)setupSubviews {
    self.customTitleLabel = [UILabel new];
    self.customTitleLabel.textAlignment = NSTextAlignmentCenter;
    self.customTitleLabel.font = [self.class customTitleFont];
    self.customTitleLabel.textColor = [UIColor qmui_colorWithHexString:@"#222222"];
    self.customTitleLabel.adjustsFontSizeToFitWidth = true;
    [self addSubview:self.customTitleLabel];
    [self.customTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self);
        make.centerX.mas_equalTo(self);
        make.width.mas_equalTo(self).offset(-10.0);
        make.height.mas_equalTo([self.class customTitleHeight]);
    }];
    //
    self.dataLabel = [UILabel new];
    self.dataLabel.font = [self.class dataFont];
    self.dataLabel.textAlignment = NSTextAlignmentCenter;
    self.dataLabel.textColor = [UIColor darkMainColor];
    self.dataLabel.adjustsFontSizeToFitWidth = true;
    [self addSubview:self.dataLabel];
    [self.dataLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self);
        make.centerX.mas_equalTo(self);
        make.width.mas_equalTo(self).offset(-10.0);
        make.height.mas_equalTo([self.class dataHeight]);
    }];
}

@end

static CGFloat BCUserCenterCoinDataTypeViewTopPadding = 0.0;

@interface BCUserCenterCoinDataTypeView ()

@property (nonatomic, strong) BCUserCenterCoinDataButtonView *lastDataButton;

@property (nonatomic, strong) BCUserCenterCoinDataButtonView *totleDataButton;

@property (nonatomic, strong) BCUserCenterCoinDataButtonView *projectDataButton;

@end

@implementation BCUserCenterCoinDataTypeView

- (instancetype)initWithCoinType:(BCCoinType)type
{
    self = [super init];
    if (self) {
        _type = type;
        [self setupSubviews];
        [self initTitleContents];
    }
    return self;
}
- (void)setupSubviews {
    self.lastDataButton = [BCUserCenterCoinDataButtonView new];
    [self addSubview:self.lastDataButton];
    //
    self.totleDataButton = [BCUserCenterCoinDataButtonView new];
    [self addSubview:self.totleDataButton];
    //
    self.projectDataButton = [BCUserCenterCoinDataButtonView new];
    [self addSubview:self.projectDataButton];
    //布局
    /**
     分5份 project 1 other 2
     */
    CGFloat buttonHeight = [BCUserCenterCoinDataButtonView defaultHeight];
    [self.lastDataButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).offset(BCUserCenterCoinDataTypeViewTopPadding);
        make.left.mas_equalTo(self);
        make.width.mas_equalTo(self).multipliedBy(2.0/5);
        make.height.mas_equalTo(buttonHeight);
    }];
    [self.projectDataButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.lastDataButton);
        make.right.mas_equalTo(self);
        make.width.mas_equalTo(self).multipliedBy(1.0/5);
        make.height.mas_equalTo(self.lastDataButton);
    }];
    [self.totleDataButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.lastDataButton);
        make.right.mas_equalTo(self.projectDataButton.mas_left);
        make.left.mas_equalTo(self.lastDataButton.mas_right);
        make.height.mas_equalTo(self.lastDataButton);
    }];
}
- (void)initTitleContents {
    NSString *coinTypeString = BConvertCoinTypeToString(self.type);
    self.lastDataButton.customTitleLabel.text = [NSString stringWithFormat:@"%@(%@)",BCLocalizedKey(@"uc_last_profit"),coinTypeString];
    self.totleDataButton.customTitleLabel.text = [NSString stringWithFormat:@"%@(%@)",BCLocalizedKey(@"uc_totle_profit"),coinTypeString];
    self.projectDataButton.customTitleLabel.text = BCLocalizedKey(@"uc_project_count");
}

- (void)setLastProfits:(NSString *)lastProfits {
    _lastProfits = lastProfits;
    self.lastDataButton.dataLabel.text = lastProfits;
}
- (void)setTotleProfits:(NSString *)totleProfits {
    _totleProfits = totleProfits;
    self.totleDataButton.dataLabel.text = totleProfits;
}
- (void)setProjects:(NSString *)projects {
    _projects = projects;
    self.projectDataButton.dataLabel.text = projects;
}

#pragma mark - add action
- (void)addLastProfitsTarget:(id)target action:(SEL)action {
    [self.lastDataButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
}
- (void)addTotleProfitsTarget:(id)target action:(SEL)action {
    [self.totleDataButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
}
- (void)addProjectsTarget:(id)target action:(SEL)action {
    [self.projectDataButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
}



+ (CGFloat)defaultHeight {
    CGFloat height = 0;
    height += BCUserCenterCoinDataTypeViewTopPadding;
    height += [BCUserCenterCoinDataButtonView defaultHeight];
    return height;
}

@end
